from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.uic import loadUiType
import sys
import pyinstaffmation
import pyeditstaffmation
import Main
import dbutil
import pyinmemmation, pyeditmemmation,pyinsuppliermation,pyeditsuppliermation,pyinpurchasemation,\
       pyeditpurchasemation,pyininventorymation,pyeditinventorymation,pyinsellmation,pyeditsellmation
mw, _ = loadUiType('mainwindow.ui')

class MWApp(QMainWindow,mw):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.registerAction.setEnabled(False)
        self.changepasswordAction.setEnabled(False)
        self.loginAction.setEnabled(False)
        self.logoutAction.setEnabled(True)
        self.exitAction.setEnabled(True)
        self.menu.triggered[QAction].connect(self.menuTriggered)
        self.instaffmationPushButton.clicked.connect(self.mainwindowToinstaffmation)
        self.inmemmationPushButton.clicked.connect(self.mainwindowToinmemmation)
        self.insuppliermationPushButton.clicked.connect(self.mainwindowToinsuppliermation)
        self.inpurchasemationPushButton.clicked.connect(self.mainwindowToinpurchasemation)
        self.ininventorymationPushButton.clicked.connect(self.mainwindowToininventorymation)
        self.insellmationPushButton.clicked.connect(self.mainwindowToinsellmation)
        self.logoutButton.clicked.connect(self.logout)
        self.handle_buttons()
        self.show_staffinformation()
        self.show_memberinformation()
        self.show_supplierinformation()
        self.show_purchaseinformation()
        self.show_inventoryinformation()
        self.show_sellinformation()
        self.tabWidget.tabBar().setVisible(False) # 隐藏标签

        self.searchButton1.clicked.connect(self.search_member)
        self.deleteButton1.clicked.connect(self.delete_member)
        self.editButton1.clicked.connect(self.edit_member1)
        self.searchButton2.clicked.connect(self.search_staff)
        self.deleteButton2.clicked.connect(self.delete_staff)
        self.editButton2.clicked.connect(self.edit_staff1)
        self.searchButton3.clicked.connect(self.search_supplier)
        self.deleteButton3.clicked.connect(self.delete_supplier)
        self.editButton3.clicked.connect(self.edit_supplier1)
        self.searchButton4.clicked.connect(self.search_purchase)
        self.deleteButton4.clicked.connect(self.delete_purchase)
        self.editButton4.clicked.connect(self.edit_purchase1)
        self.searchButton5.clicked.connect(self.search_inventory)
        self.deleteButton5.clicked.connect(self.delete_inventory)
        self.editButton5.clicked.connect(self.edit_inventory1)
        self.searchButton6.clicked.connect(self.search_sell)
        self.deleteButton6.clicked.connect(self.delete_sell)
        self.editButton6.clicked.connect(self.edit_sell1)






#############菜单栏函数########################################
    def menuTriggered(self, q):
        if (q.text() == "退出登录"):
            self.login_app = Main.LoginApp()
            self.close()
            self.login_app.show()

        if (q.text() == "退出"):
            app = QApplication.instance()
            app.quit()
        return
#######退出登录函数#################
    def logout(self):
        app = QApplication.instance()
        app.quit()

######主窗口跳转到添加、编辑员工信息界面#########################################
    def mainwindowToinstaffmation(self):
        self.instaffmation_app =pyinstaffmation.instaffmationApp()
        self.close()
        self.instaffmation_app.show()

    def mainwindowToeditstaffmation(self):
        self.editstaffmation_app =pyeditstaffmation.editstaffmationApp()
        self.close()
        self.editstaffmation_app.show()
    def mainwindowToinmemmation(self):
        self.inmembermation_app =pyinmemmation.inmembermationApp()
        self.close()
        self.inmembermation_app.show()


    def mainwindowToeditmemmation(self):
        self.editmembermation_app =pyeditmemmation.editmemmationApp()
        self.close()
        self.editmembermation_app.show()
    def mainwindowToinsuppliermation(self):
        self.insuppliermation_app =pyinsuppliermation.insuppliermationApp()
        self.close()
        self.insuppliermation_app.show()
    def mainwindowToeditsuppliermation(self):
        self.editsuppliermation_app =pyeditsuppliermation.editsuppliermationApp()
        self.close()
        self.editsuppliermation_app.show()
    def mainwindowToinpurchasemation(self):
        self.inpurchasemation_app = pyinpurchasemation.inpurchasemationApp()
        self.close()
        self.inpurchasemation_app.show()
    def mainwindowToeditpurchasemation(self):
        self.editpurchasemation_app =pyeditpurchasemation.editpurchasemationApp()
        self.close()
        self.editpurchasemation_app.show()
    def mainwindowToininventorymation(self):
        self.ininventorymation_app = pyininventorymation.ininventorymationApp()
        self.close()
        self.ininventorymation_app.show()
    def mainwindowToeditinventorymation(self):
        self.editinventorymation_app =pyeditinventorymation.editinventorymationApp()
        self.close()
        self.editinventorymation_app.show()
    def mainwindowToinsellmation(self):
        self.insellmation_app = pyinsellmation.insellmationApp()
        self.close()
        self.insellmation_app.show()
    def mainwindowToeditsellmation(self):
        self.editsellmation_app =pyeditsellmation.editsellmationApp()
        self.close()
        self.editsellmation_app.show()


    #所有Button的消息与槽的通信
    def handle_buttons(self):

        self.informationButton.clicked.connect(lambda:self.open_information_tab())
        self.purchaseButton.clicked.connect(lambda:self.open_purchase_tab())
        self.inventoryButton.clicked.connect(lambda: self.open_inventory_tab())
        self.sellButton.clicked.connect(lambda: self.open_sell_tab())


    #选项卡联动
    def open_information_tab(self):
        self.tabWidget.setCurrentIndex(0)
    def open_purchase_tab(self):
        self.tabWidget.setCurrentIndex(1)
    def open_inventory_tab(self):
        self.tabWidget.setCurrentIndex(2)
    def open_sell_tab(self):
        self.tabWidget.setCurrentIndex(3)



#################################################################
    #搜索会员信息
    def search_member(self):
        if self.comboBox1.currentText()=='':
            self.show_memberinformation()
        if self.comboBox1.currentText() == "按会员编号搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from memberinformation where 会员编号 like %s"
            membernum=self.lineEdit1.text()
            membernum1 = '%'+membernum+'%'
            cur.execute(sql1, (membernum1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.memberTable.setRowCount(0)
                self.memberTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.memberTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.memberTable.rowCount()
                    self.memberTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()
                #self.memberTable.clear()
        if self.comboBox1.currentText() == "按姓名搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql2 = "select * from memberinformation where 姓名 like %s"
            membername = self.lineEdit1.text()
            membername1 = '%' + membername + '%'
            cur.execute(sql2, (membername1,))
            data = cur.fetchall()
            print(data)
            if data:
                self.memberTable.setRowCount(0)
                self.memberTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.memberTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.memberTable.rowCount()
                    self.memberTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()
                #self.memberTable.clear()

        if self.comboBox1.currentText() == "按会员类别搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql3 = "select * from memberinformation where 会员类别 like %s"
            membersort = self.lineEdit1.text()
            membersort1 = '%' + membersort + '%'
            cur.execute(sql3, (membersort1,))
            data = cur.fetchall()
            print(data)
            if data:
                self.memberTable.setRowCount(0)
                self.memberTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.memberTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.memberTable.rowCount()
                    self.memberTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                # self.lineEdit1.clear()
                #self.memberTable.clear()

    #删除会员信息
    def delete_member(self):
        col = self.memberTable.currentColumn()
        row = self.memberTable.currentRow()
        if self.memberTable.item(row, col) == None:
            QMessageBox.information(self, "警告", "删除不可为空！",QMessageBox.Yes)
            return

        membernumber = self.memberTable.selectedItems()[0].text()
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from memberinformation where 会员编号 =%s"
        cur.execute(sql, (membernumber, ))
        data = cur.fetchone()

        if data:
            warning = QMessageBox.warning(self, "提示", "确定删除此条信息吗？", QMessageBox.Yes | QMessageBox.No)
            if warning == QMessageBox.Yes:
                sql = "delete from memberinformation where 会员编号 =%s"
                cur.execute(sql, (membernumber,))
                conn.commit()
                dbutil.close_conn(conn, cur)
                QMessageBox.information(self, "提示", "删除成功！",QMessageBox.Yes)

        else:
            QMessageBox.information(self, "提示", "请选择需要删除的信息",QMessageBox.Yes)
        self.show_memberinformation()  # 调用显示函数

    #修改会员信息
    def edit_member1(self):
        col = self.memberTable.currentColumn()
        row = self.memberTable.currentRow()
        if self.memberTable.item(row, col) == None:
            QMessageBox.information(self, "提示", "编辑不可为空！",QMessageBox.Yes)
            return
        # 获取连接
        conn = dbutil.get_conn()
        # 获取cursor
        cur = conn.cursor()
        # SQL语句
        sql = "select * from memberinformation where 会员编号 =%s"
        membernumber = self.memberTable.selectedItems()[0].text()
        # 执行语句
        cur.execute(sql, (membernumber, ))
        data = cur.fetchone()
        if data:
            self.mainwindowToeditmemmation()
            self.editmembermation_app.numEdit.setText(data[0])
            self.editmembermation_app.nameEdit.setText(data[1])
            self.editmembermation_app.sexEdit.setText(data[2])
            self.editmembermation_app.categoryEdit.setText(data[3])
            self.editmembermation_app.phoneEdit.setText(data[4])

    #搜索员工信息
    def search_staff(self):
        if self.comboBox2.currentText()=='':
            self.show_staffinformation()
        if self.comboBox2.currentText() == "按员工编号搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from staffinformation where 员工编号 like %s"
            staffnum=self.lineEdit2.text()
            staffnum1 = '%'+staffnum+'%'
            cur.execute(sql1, (staffnum1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.staffTable.setRowCount(0)
                self.staffTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.staffTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.staffTable.rowCount()
                    self.staffTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit2.clear()
                #self.staffTable.clear()
        if self.comboBox2.currentText() == "按职位搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql2 = "select * from staffinformation where 职位 like %s"
            staffposition = self.lineEdit2.text()
            staffposition1 = '%' + staffposition + '%'
            cur.execute(sql2, (staffposition1,))
            data = cur.fetchall()
            print(data)
            if data:
                self.staffTable.setRowCount(0)
                self.staffTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.staffTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.staffTable.rowCount()
                    self.staffTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit2.clear()
                #self.staffTable.clear()

        if self.comboBox2.currentText() == "按所在部门搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql3 = "select * from staffinformation where 所在部门 like %s"
            staffdepart = self.lineEdit2.text()
            staffdepart1 = '%' + staffdepart + '%'
            cur.execute(sql3, (staffdepart1,))
            data = cur.fetchall()
            print(data)
            if data:
                self.staffTable.setRowCount(0)
                self.staffTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.staffTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.staffTable.rowCount()
                    self.staffTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                # self.lineEdit2.clear()
                #self.staffTable.clear()

        if self.comboBox2.currentText() == "按入职时间搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql3 = "select * from staffinformation where 入职时间 like %s"
            stafftime = self.lineEdit2.text()
            stafftime1 = '%' + stafftime + '%'
            cur.execute(sql3, (stafftime1,))
            data = cur.fetchall()
            print(data)
            if data:
                self.staffTable.setRowCount(0)
                self.staffTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.staffTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.staffTable.rowCount()
                    self.staffTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                # self.lineEdit2.clear()
                #self.staffTable.clear()

    #删除员工信息
    def delete_staff(self):
        col = self.staffTable.currentColumn()
        row = self.staffTable.currentRow()
        if self.staffTable.item(row, col) == None:
            QMessageBox.information(self, "警告", "删除不可为空！",QMessageBox.Yes)
            return

        staffnumber = self.staffTable.selectedItems()[0].text()
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from staffinformation where 员工编号 =%s"
        cur.execute(sql, (staffnumber, ))
        data = cur.fetchone()

        if data:
            warning = QMessageBox.warning(self, "提示", "确定删除此条信息吗？", QMessageBox.Yes | QMessageBox.No)
            if warning == QMessageBox.Yes:
                sql = "delete from staffinformation where 员工编号 =%s"
                cur.execute(sql, (staffnumber,))
                conn.commit()
                dbutil.close_conn(conn, cur)
                QMessageBox.information(self, "提示", "删除成功！",QMessageBox.Yes)

        else:
            QMessageBox.information(self, "提示", "请选择需要删除的信息",QMessageBox.Yes)
        self.show_staffinformation()  # 调用显示函数

    #修改员工信息
    def edit_staff1(self):
        col = self.staffTable.currentColumn()
        row = self.staffTable.currentRow()
        if self.staffTable.item(row, col) == None:
            QMessageBox.information(self, "提示", "编辑不可为空！",QMessageBox.Yes)
            return
        # 获取连接
        conn = dbutil.get_conn()
        # 获取cursor
        cur = conn.cursor()
        # SQL语句
        sql = "select * from staffinformation where 员工编号 =%s"
        staffnumber = self.staffTable.selectedItems()[0].text()
        # 执行语句
        cur.execute(sql, (staffnumber, ))
        data = cur.fetchone()
        if data:
            self.mainwindowToeditstaffmation()
            self.editstaffmation_app.numEdit.setText(data[0])
            self.editstaffmation_app.nameEdit.setText(data[1])
            self.editstaffmation_app.sexEdit.setText(data[2])
            self.editstaffmation_app.positionEdit.setText(data[3])
            self.editstaffmation_app.departmentEdit.setText(data[4])
            self.editstaffmation_app.phoneEdit.setText(data[5])
            self.editstaffmation_app.beginEdit.setText(data[6])

    #搜索供应商信息
    def search_supplier(self):
        if self.comboBox3.currentText()=='':
            self.show_supplierinformation()
        if self.comboBox3.currentText() == "按地址搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from supplierinformation where 地址 like %s"
            place=self.lineEdit3.text()
            place1 = '%'+place+'%'
            cur.execute(sql1, (place1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.supplierTable.setRowCount(0)
                self.supplierTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.supplierTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.supplierTable.rowCount()
                    self.supplierTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit3.clear()
                #self.supplierTable.clear()

        if self.comboBox3.currentText() == "按供应商姓名搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql2 = "select * from supplierinformation where 供应商姓名 like %s"
            name=self.lineEdit3.text()
            name1 = '%'+name+'%'
            cur.execute(sql2, (name1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.supplierTable.setRowCount(0)
                self.supplierTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.supplierTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.supplierTable.rowCount()
                    self.supplierTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit3.clear()
                #self.supplierTable.clear()

    #删除供应商信息
    def delete_supplier(self):
        col = self.supplierTable.currentColumn()
        row = self.supplierTable.currentRow()
        if self.supplierTable.item(row, col) == None:
            QMessageBox.information(self, "警告", "删除不可为空！", QMessageBox.Yes)
            return

        supplier = self.supplierTable.selectedItems()[0].text()
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from supplierinformation where 供应商姓名 =%s"
        cur.execute(sql, (supplier,))
        data = cur.fetchone()

        if data:
            warning = QMessageBox.warning(self, "提示", "确定删除此条信息吗？", QMessageBox.Yes | QMessageBox.No)
            if warning == QMessageBox.Yes:
                sql = "delete from supplierinformation where 供应商姓名 =%s"
                cur.execute(sql, (supplier,))
                conn.commit()
                dbutil.close_conn(conn, cur)
                QMessageBox.information(self, "提示", "删除成功！", QMessageBox.Yes)

        else:
            QMessageBox.information(self, "提示", "请选择需要删除的信息", QMessageBox.Yes)
        self.show_supplierinformation()  # 调用显示函数

    #修改供应商信息
    def edit_supplier1(self):
        col = self.supplierTable.currentColumn()
        row = self.supplierTable.currentRow()
        if self.supplierTable.item(row, col) == None:
            QMessageBox.information(self, "提示", "编辑不可为空！", QMessageBox.Yes)
            return
        # 获取连接
        conn = dbutil.get_conn()
        # 获取cursor
        cur = conn.cursor()
        # SQL语句
        sql = "select * from supplierinformation where 供应商姓名 =%s"
        name = self.supplierTable.selectedItems()[0].text()
        # 执行语句
        cur.execute(sql, (name,))
        data = cur.fetchone()
        if data:
            self.mainwindowToeditsuppliermation()
            self.editsuppliermation_app.nameEdit.setText(data[0])
            self.editsuppliermation_app.sexEdit.setText(data[1])
            self.editsuppliermation_app.placeEdit.setText(data[2])
            self.editsuppliermation_app.phoneEdit.setText(data[3])

    #搜索进货信息
    def search_purchase(self):
        if self.comboBox4.currentText()=='':
            self.show_purchaseinformation()
        if self.comboBox4.currentText() == "按进货编号搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from purchase where 进货编号 like %s"
            num=self.lineEdit4.text()
            num1 = '%'+num+'%'
            cur.execute(sql1, (num1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.purchaseTable.setRowCount(0)
                self.purchaseTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.purchaseTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.purchaseTable.rowCount()
                    self.purchaseTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()


        if self.comboBox4.currentText() == "按商品名称搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from purchase where 商品名称 like %s"
            name=self.lineEdit4.text()
            name1 = '%'+name+'%'
            cur.execute(sql1, (name1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.purchaseTable.setRowCount(0)
                self.purchaseTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.purchaseTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.purchaseTable.rowCount()
                    self.purchaseTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()
                #self.purchaseTable.clear()
        if self.comboBox4.currentText() == "按进货员搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from purchase where 进货员 like %s"
            name=self.lineEdit4.text()
            name1 = '%'+name+'%'
            cur.execute(sql1, (name1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.purchaseTable.setRowCount(0)
                self.purchaseTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.purchaseTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.purchaseTable.rowCount()
                    self.purchaseTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()
                #self.purchaseTable.clear()
        if self.comboBox4.currentText() == "按进货时间搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from purchase where 进货时间 like %s"
            name=self.lineEdit4.text()
            name1 = '%'+name+'%'
            cur.execute(sql1, (name1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.purchaseTable.setRowCount(0)
                self.purchaseTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.purchaseTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.purchaseTable.rowCount()
                    self.purchaseTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()
                #self.purchaseTable.clear()

    #删除进货信息
    def delete_purchase(self):
        col = self.purchaseTable.currentColumn()
        row = self.purchaseTable.currentRow()
        if self.purchaseTable.item(row, col) == None:
            QMessageBox.information(self, "警告", "删除不可为空！", QMessageBox.Yes)
            return

        purchase = self.purchaseTable.selectedItems()[0].text()
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from purchase where 进货编号 =%s"
        cur.execute(sql, (purchase,))
        data = cur.fetchone()

        if data:
            warning = QMessageBox.warning(self, "提示", "确定删除此条信息吗？", QMessageBox.Yes | QMessageBox.No)
            if warning == QMessageBox.Yes:
                sql = "delete from purchase where 进货编号 =%s"
                cur.execute(sql, (purchase,))
                conn.commit()
                dbutil.close_conn(conn, cur)
                QMessageBox.information(self, "提示", "删除成功！", QMessageBox.Yes)

        else:
            QMessageBox.information(self, "提示", "请选择需要删除的信息", QMessageBox.Yes)
        self.show_purchaseinformation()  # 调用显示函数

    #修改进货信息
    def edit_purchase1(self):
        col = self.purchaseTable.currentColumn()
        row = self.purchaseTable.currentRow()
        if self.purchaseTable.item(row, col) == None:
            QMessageBox.information(self, "提示", "编辑不可为空！", QMessageBox.Yes)
            return
        # 获取连接
        conn = dbutil.get_conn()
        # 获取cursor
        cur = conn.cursor()
        # SQL语句
        sql = "select * from purchase where 进货编号 =%s"
        num = self.purchaseTable.selectedItems()[0].text()
        # 执行语句
        cur.execute(sql, (num,))
        data = cur.fetchone()
        if data:
            self.mainwindowToeditpurchasemation()
            self.editpurchasemation_app.numEdit.setText(data[0])
            self.editpurchasemation_app.goodsnameEdit.setText(data[1])
            self.editpurchasemation_app.quantityEdit.setText(data[2])
            self.editpurchasemation_app.quantityunitEdit.setText(data[3])
            self.editpurchasemation_app.buyerEdit.setText(data[4])
            self.editpurchasemation_app.sellerEdit.setText(data[5])
            self.editpurchasemation_app.moneyEdit.setText(data[6])
            self.editpurchasemation_app.dateEdit.setText(data[7])

    #搜索库存信息
    def search_inventory(self):
        if self.comboBox5.currentText()=='':
            self.show_inventoryinformation()
        if self.comboBox5.currentText() == "按商品名称搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from inventory where 商品名称 like %s"
            name=self.lineEdit5.text()
            name1 = '%'+name+'%'
            cur.execute(sql1, (name1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.inventoryTable.setRowCount(0)
                self.inventoryTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.inventoryTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.inventoryTable.rowCount()
                    self.inventoryTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()
        if self.comboBox5.currentText() == "按存放仓库搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from inventory where 存放仓库 like %s"
            name=self.lineEdit5.text()
            name1 = '%'+name+'%'
            cur.execute(sql1, (name1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.inventoryTable.setRowCount(0)
                self.inventoryTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.inventoryTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.inventoryTable.rowCount()
                    self.inventoryTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()

    #删除库存信息
    def delete_inventory(self):
        col = self.inventoryTable.currentColumn()
        row = self.inventoryTable.currentRow()
        if self.inventoryTable.item(row, col) == None:
            QMessageBox.information(self, "警告", "删除不可为空！", QMessageBox.Yes)
            return

        inventory = self.inventoryTable.selectedItems()[0].text()
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from inventory where 商品名称 =%s"
        cur.execute(sql, (inventory,))
        data = cur.fetchone()

        if data:
            warning = QMessageBox.warning(self, "提示", "确定删除此条信息吗？", QMessageBox.Yes | QMessageBox.No)
            if warning == QMessageBox.Yes:
                sql = "delete from inventory where 商品名称 =%s"
                cur.execute(sql, (inventory,))
                conn.commit()
                dbutil.close_conn(conn, cur)
                QMessageBox.information(self, "提示", "删除成功！", QMessageBox.Yes)

        else:
            QMessageBox.information(self, "提示", "请选择需要删除的信息", QMessageBox.Yes)
        self.show_inventoryinformation()  # 调用显示函数

    #修改库存信息
    def edit_inventory1(self):
        col = self.inventoryTable.currentColumn()
        row = self.inventoryTable.currentRow()
        if self.inventoryTable.item(row, col) == None:
            QMessageBox.information(self, "提示", "编辑不可为空！", QMessageBox.Yes)
            return
        # 获取连接
        conn = dbutil.get_conn()
        # 获取cursor
        cur = conn.cursor()
        # SQL语句
        sql = "select * from inventory where 商品名称 =%s"
        num = self.inventoryTable.selectedItems()[0].text()
        # 执行语句
        cur.execute(sql, (num,))
        data = cur.fetchone()
        if data:
            self.mainwindowToeditinventorymation()
            self.editinventorymation_app.goodsnameEdit.setText(data[0])
            self.editinventorymation_app.quantityEdit.setText(data[1])
            self.editinventorymation_app.quantityunitEdit.setText(data[2])
            self.editinventorymation_app.warehouseEdit.setText(data[3])
            self.editinventorymation_app.purchaseEdit.setText(data[4])
            self.editinventorymation_app.sellEdit.setText(data[5])
            self.editinventorymation_app.staffEdit.setText(data[6])

    #搜索销售信息
    def search_sell(self):
        if self.comboBox6.currentText()=='':
            self.show_sellinformation()
        if self.comboBox6.currentText() == "按销售编号搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from sell where 销售编号 like %s"
            num=self.lineEdit6.text()
            num1 = '%'+num+'%'
            cur.execute(sql1, (num1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.sellTable.setRowCount(0)
                self.sellTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.sellTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.sellTable.rowCount()
                    self.sellTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()

        if self.comboBox6.currentText() == "按商品名称搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from sell where 商品名称 like %s"
            name=self.lineEdit6.text()
            name1 = '%'+name+'%'
            cur.execute(sql1, (name1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.sellTable.setRowCount(0)
                self.sellTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.sellTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.sellTable.rowCount()
                    self.sellTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()

        if self.comboBox6.currentText() == "按销售员工搜索":
            conn = dbutil.get_conn()
            cur = conn.cursor()
            sql1 = "select * from sell where 销售员工 like %s"
            num=self.lineEdit6.text()
            num1 = '%'+num+'%'
            cur.execute(sql1, (num1,))
            data = cur.fetchall()
            print(data)

            if data:
                self.sellTable.setRowCount(0)
                self.sellTable.insertRow(0)
                for row, form in enumerate(data):
                    for column, item in enumerate(form):
                        self.sellTable.setItem(row, column, QTableWidgetItem(str(item)))
                        column += 1
                    row_position = self.sellTable.rowCount()
                    self.sellTable.insertRow(row_position)
            else:
                QMessageBox.information(self, "提示", "没有符合要求的信息!", QMessageBox.Yes)
                #self.lineEdit1.clear()

    #删除销售信息
    def delete_sell(self):
        col = self.sellTable.currentColumn()
        row = self.sellTable.currentRow()
        if self.sellTable.item(row, col) == None:
            QMessageBox.information(self, "警告", "删除不可为空！", QMessageBox.Yes)
            return

        sell = self.sellTable.selectedItems()[0].text()
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from sell where 销售编号 =%s"
        cur.execute(sql, (sell,))
        data = cur.fetchone()

        if data:
            warning = QMessageBox.warning(self, "提示", "确定删除此条信息吗？", QMessageBox.Yes | QMessageBox.No)
            if warning == QMessageBox.Yes:
                sql = "delete from sell where 销售编号 =%s"
                cur.execute(sql, (sell,))
                conn.commit()
                dbutil.close_conn(conn, cur)
                QMessageBox.information(self, "提示", "删除成功！", QMessageBox.Yes)

        else:
            QMessageBox.information(self, "提示", "请选择需要删除的信息", QMessageBox.Yes)
        self.show_sellinformation()  # 调用显示函数

    #修改销售信息
    def edit_sell1(self):
        col = self.sellTable.currentColumn()
        row = self.sellTable.currentRow()
        if self.sellTable.item(row, col) == None:
            QMessageBox.information(self, "提示", "编辑不可为空！", QMessageBox.Yes)
            return
        # 获取连接
        conn = dbutil.get_conn()
        # 获取cursor
        cur = conn.cursor()
        # SQL语句
        sql = "select * from sell where 销售编号 =%s"
        num = self.sellTable.selectedItems()[0].text()
        # 执行语句
        cur.execute(sql, (num,))
        data = cur.fetchone()
        if data:
            self.mainwindowToeditsellmation()
            self.editsellmation_app.numEdit.setText(data[0])
            self.editsellmation_app.goodsnameEdit.setText(data[1])
            self.editsellmation_app.quantityEdit.setText(data[2])
            self.editsellmation_app.quantityunitEdit.setText(data[3])
            self.editsellmation_app.moneyEdit.setText(data[4])
            self.editsellmation_app.staffEdit.setText(data[5])


































    #显示已有的员工信息，并且添加完毕后直接可以看到
    def show_staffinformation(self):
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from staffinformation"
        cur.execute(sql)
        data = cur.fetchall()
        print(data)

        if data:
            self.staffTable.setRowCount(0)
            self.staffTable.insertRow(0)
            for row, form in enumerate(data):
                for column, item in enumerate(form):
                    self.staffTable.setItem(row, column, QTableWidgetItem(str(item)))
                    column += 1
                row_position = self.staffTable.rowCount()
                self.staffTable.insertRow(row_position)

    #显示已有的会员信息，并且添加完毕后直接可以看到
    def show_memberinformation(self):
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from memberinformation"
        cur.execute(sql)
        data = cur.fetchall()
        print(data)

        if data:
            self.memberTable.setRowCount(0)
            self.memberTable.insertRow(0)
            for row, form in enumerate(data):
                for column, item in enumerate(form):
                    self.memberTable.setItem(row, column, QTableWidgetItem(str(item)))
                    column += 1
                row_position = self.memberTable.rowCount()
                self.memberTable.insertRow(row_position)


    #显示已有的供应商信息，并且添加完毕后直接可以看到
    def show_supplierinformation(self):
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from supplierinformation"
        cur.execute(sql)
        data = cur.fetchall()
        print(data)

        if data:
            self.supplierTable.setRowCount(0)
            self.supplierTable.insertRow(0)
            for row, form in enumerate(data):
                for column, item in enumerate(form):
                    self.supplierTable.setItem(row, column, QTableWidgetItem(str(item)))
                    column += 1
                row_position = self.supplierTable.rowCount()
                self.supplierTable.insertRow(row_position)

    #显示已有的进货信息，并且添加完毕后直接可以看到
    def show_purchaseinformation(self):
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from purchase"
        cur.execute(sql)
        data = cur.fetchall()
        print(data)

        if data:
            self.purchaseTable.setRowCount(0)
            self.purchaseTable.insertRow(0)
            for row, form in enumerate(data):
                for column, item in enumerate(form):
                    self.purchaseTable.setItem(row, column, QTableWidgetItem(str(item)))
                    column += 1
                row_position = self.purchaseTable.rowCount()
                self.purchaseTable.insertRow(row_position)

    #显示已有的库存信息，并且添加完毕后直接可以看到
    def show_inventoryinformation(self):
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from inventory"
        cur.execute(sql)
        data = cur.fetchall()
        print(data)

        if data:
            self.inventoryTable.setRowCount(0)
            self.inventoryTable.insertRow(0)
            for row, form in enumerate(data):
                for column, item in enumerate(form):
                    self.inventoryTable.setItem(row, column, QTableWidgetItem(str(item)))
                    column += 1
                row_position = self.inventoryTable.rowCount()
                self.inventoryTable.insertRow(row_position)

    #显示已有的销售信息，并且添加完毕后直接可以看到
    def show_sellinformation(self):
        conn = dbutil.get_conn()
        cur = conn.cursor()
        sql = "select * from sell"
        cur.execute(sql)
        data = cur.fetchall()
        print(data)

        if data:
            self.sellTable.setRowCount(0)
            self.sellTable.insertRow(0)
            for row, form in enumerate(data):
                for column, item in enumerate(form):
                    self.sellTable.setItem(row, column, QTableWidgetItem(str(item)))
                    column += 1
                row_position = self.sellTable.rowCount()
                self.sellTable.insertRow(row_position)








def main():
    app = QApplication([])     # 创建应用程序 创建一个QApplication，也就是你要开发的软件app
    window = MWApp()         # 创建主窗口  创建一个MainAPP，用来装载你需要的各种组件、控件
    window.show()              # 显示窗口 执行QMainWindow的show()方法，显示这个QMainWindow
    app.exec_()                # 使用exit()或者点击关闭按钮退出QApplication


if __name__ == '__main__':
    main()